import {http} from "@/service/http";
import {Page, PageQuery} from "@/types/response";
import {TaskJob, TaskNameSpace} from "@/types/system";

const prefix = '/TaskQz'

/**
 * 删除一个任务
 * @param jobId
 * @returns
 */
export const removeTask = (jobId: string | number) => {
  return http({
    method: 'DELETE',
    url: `${prefix}/Delete`,
    params: {
      jobId
    }
  })
}

/**
 * 立即执行一个任务
 * @param jobId
 * @returns
 */
export const executeJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/ExecuteJob`,
    params: {
      jobId
    }
  })
}


/**
 * 分页获取任务
 * @param page
 * @returns
 */
export const getTaskByPage = (page: PageQuery) => {
  return http<Page<TaskJob[]>>({
    method: 'GET',
    url: `${prefix}/Get`,
    params: {
      ...page
    }
  })
}


/**
 * 获取任务明明空间
 * @param jobId
 * @returns
 */
export const getTaskNameSpace = (jobId: string | number) => {
  return http<TaskNameSpace>({
    method: 'GET',
    url: `${prefix}/GetTaskNameSpace`,
    params: {
      jobId
    }
  })
}

/**
 * 暂停一个计划任务
 * @param jobId jobId
 * @returns
 */
export const pauseJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/PauseJob`,
    params: {
      jobId
    }
  })
}


/**
 * 创建一个任务
 * @returns
 */
export const createJobTask = (task: TaskJob) => {
  return http({
    method: 'POST',
    url: `${prefix}/Post`,
    data: {
      ...task
    }
  })
}

/**
 * 修改一个任务
 * @param task
 * @returns
 */
export const updateJobTask = (task: TaskJob) => {
  return http({
    method: 'Put',
    url: `${prefix}/Put/`,
    data: {
      ...task
    }
  })
}


/**
 * 重启一个任务
 * @param jobId
 * @returns
 */
export const recoveryJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/ReCovery`,
    params: {
      jobId
    }
  })
}


/**
 * 修复一个计划任务
 * @param jobId
 * @returns
 */
export const resumeJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/ResumeJob`,
    params: {
      jobId
    }
  })
}


/**
 * 启动计划任务
 * @param jobId
 * @returns
 */
export const startJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/StartJob`,
    params: {
      jobId
    }
  })
}

/**
 * 停止一个任务
 * @param jobId
 * @returns
 */
export const stopJob = (jobId: string | number) => {
  return http({
    method: 'GET',
    url: `${prefix}/StopJob`,
    params: {
      jobId
    }
  })
}
